package com.songcan.oauth.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.songcan.model.oauth.SysRole;
import com.songcan.oauth.service.SysRoleService;
import com.songcan.oauth.vo.RoleVO;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Objects;

@RestController
@RequestMapping("rest/role")
@Validated
@AllArgsConstructor
public class RoleController {

    private final SysRoleService sysRoleService;



    @PostMapping()
    public void addRole(@NotBlank(message = "名称不能为空")String name,
                        String roleCode,String roleDesc,String... menuIds){

         sysRoleService.addRole(name,roleCode,roleDesc,menuIds);
    }

    @PutMapping()
    public void updateRole(@NotNull(message = "roleId不能为空")Long id,
                           String name,String roleCode,String roleDesc,String... menuIds){
        sysRoleService.updateRole(id,name,roleCode,roleDesc,menuIds);
    }


    @GetMapping()
    public RoleVO getByRoleVO(@NotNull(message = "id不能为空")Long id ){
         return sysRoleService.selectByDetail(id);
    }

    @GetMapping("/list")
    public IPage<SysRole>  sysRoleIPage(@RequestParam(defaultValue = "1")Integer page,
                                        @RequestParam(defaultValue = "20")Integer pageSize,
                                        String keyWord){

        return sysRoleService.selectByRolePage(new Page(page,pageSize),keyWord);
    }


}
